package com.proxy.scanandcheck.checker.service;

import org.apache.http.client.HttpClient;
import org.apache.log4j.Logger;

import com.proxy.scanandcheck.checker.dao.ProxyDao;
import com.proxy.scanandcheck.checker.http.proxy.ClientExecuteProxy;
import com.proxy.scanandcheck.checker.http.proxy.ClientExecuteProxyCheckGoogleHost;
import com.proxy.scanandcheck.common.valueobject.Proxy;

/**
 * Check proxy valid class.
 * @author paul
 *
 */
public class ProxyService {
	
	private static final Logger LOGGER = Logger.getLogger(ProxyService.class);
	
	/**
	 * check proxy if it is a valid for google, save to proxies table 
	 * @param myProxy
	 * @throws Exception
	 */
	public void checkProxy(HttpClient httpclient,Proxy myProxy,String keyword) throws Exception
	{
        
		ClientExecuteProxy clientExecuteProxyGoogle = new ClientExecuteProxyCheckGoogleHost(httpclient,myProxy,keyword);
		clientExecuteProxyGoogle.execue();
		
		LOGGER.info("------- finish checking proxy: " + myProxy);
		
		if(myProxy.isValidForGoogleHost())
		{
			ProxyDao proxyDao = new ProxyDao();
			proxyDao.createOrUpdateProxies(myProxy);
		}
	}
}
